<template>
  <div class="wrap">
    <!-- <van-search
      v-model="value"
      shape="round"
      background="#F2F4FA"
      show-action
      placeholder="请输入搜索内容"
      @search="onSearch"
    >
      <div @click="onSearch">搜索</div>
    </van-search> -->
    <div class="listWrap" v-if="resSchoolList.length > 0">
      <div
        class="lineItem"
        v-for="(item, index) in resSchoolList"
        :key="index"
        @click="chooseItemJump(item.id, item.addressName)"
      >
        {{ item.addressName }}
      </div>
    </div>
    <div class="listWrap" v-else>暂无学校，等待录入...</div>
  </div>
</template>

<script>
import { Search } from "vant";
import { apiAddressList } from "@/request/api";
export default {
  name: "App",
  data() {
    return {
      value: "",
      resSchoolList: "", //校区列表
      fromId: this.$route.query.fromId,
      isHaveAddr: this.$route.query.isHaveAddr,
      reqShopId: this.$route.query.shopId, //店铺id
    };
  },
  mounted() {
    document.querySelector("body").setAttribute("style", "background-color:#F2F4FA");
    this.getAddressList();
    console.log("fromId", this.fromId);
  },
  methods: {
    //获取校区列表：
    getAddressList() {
      apiAddressList({
        id: -1,
      }).then((res) => {
        this.resSchoolList = res.data;
        console.log("校区列表", this.resSchoolList);
      });
    },
    chooseItemJump(id, name) {
      var chooseSchoolData = {
        schoolId: id,
        schoolIName: name,
      };
      sessionStorage.setItem("chooseSchoolData", JSON.stringify(chooseSchoolData));
      console.log("选择校区", chooseSchoolData, this.fromId);
      if (this.fromId == 0) {
        //从登录强制添加地址来的 (更改为支付添加收货信息)
        this.$router.push({
          path: "/pages/addReciveAddr",
          query: {
            chooseSchoolData: chooseSchoolData,
            formId: this.fromId,
            isHaveAddr: this.isHaveAddr,
            shopId: this.reqShopId,
          },
        });
      } else if (this.fromId == 2) {
        //从首页选择校区来的
        console.log("dd22");
        sessionStorage.setItem("changeSchoolData", JSON.stringify(chooseSchoolData));
        this.$router.push({ path: "/", query: { formId: this.fromId,chooseSchoolData: chooseSchoolData } });
      } else if (this.fromId == 3) {
        //从商家入住填写申请资料来的 BecomeBusinessman
        this.$router.push({
          path: "/pages/BecomeBusinessman",
          query: { formId: this.fromId,chooseSchoolData: chooseSchoolData },
        });
      } else if (this.fromId == 4) {
        //从商家第一次进入首页填写店铺资料来的 fillShopInfomation
        this.$router.push({
          path: "/pages/fillShopInfomation",
          query: { formId: this.fromId,chooseSchoolData: chooseSchoolData },
        });
      }else if (this.fromId == 5) { //个人中心编辑资料来的5
        //从首页选择校区来的
        console.log("dd55");
        sessionStorage.setItem("changeSchoolData", JSON.stringify(chooseSchoolData));
        this.$router.push({ path: "/pages/addReciveAddr", query: {  formId: this.fromId,chooseSchoolData: chooseSchoolData } });
      }
    },
    onSearch() {},
  },
  created() {},
  components: {
    [Search.name]: Search,
  },
};
</script>

<style scoped>
.van-search__content {
  background-color: #fff;
}
.listWrap {
  background-color: #fff;
  width: 90%;
  margin: 20px auto;
  border-radius: 20px;
}
.lineItem {
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  margin-left: 10px;
}
</style>
